package com.app.service.system

import com.app.constant.CommonConstant
import com.app.mapper.TUserMapper
import com.app.model.TRole
import com.app.service.BaseService
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service


/**
 * Created by three on 14-8-4.
 */
@CompileStatic
@TypeChecked
@Service
class RoleService extends BaseService<TRole> implements IRoleService {

    @Autowired
    void setMapper(TUserMapper mapper) {
        super.baseMapper = mapper;
    }

    @Override
    Long addBasic(TRole obj) throws Exception {
        TRole role = obj as TRole;
        role.setCreateTime(new Date());
        role.setCreateUserId(0L);
        role.setIsActive(CommonConstant.IsActive.TRUE.getValue() as Boolean);
        return baseMapper.insert(role);
    }

    @Override
    void modifyBasic(TRole obj) throws Exception {
        TRole role = obj as TRole;
        role.setCreateTime(null);
        role.setCreateUserId(null);
        baseMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    void delBasic(TRole obj) throws Exception {
        TRole role = new TRole(id: (obj as TRole).id, isActive: CommonConstant.IsActive.FALSE.getValue() as Boolean);
        baseMapper.updateByPrimaryKeySelective(role);
    }

}
